package com.centaline.androidsalesblog.utils;

import android.text.TextUtils;

import com.centaline.androidsalesblog.constants.CommonConstant;
import com.centaline.androidsalesblog.model.businissobject.DropBo;

import java.math.BigDecimal;
import java.util.Locale;

/**
 * 下拉菜单工具类
 * Created by guilin on 16/1/27.
 */
public final class DropUtil {

    private DropUtil() {
        //Utility Class
    }

    /**
     * 比较值
     *
     * @param dropBo DropBo
     */
    public static boolean compareValue(DropBo dropBo) {
        return CommonConstant.DROP_VALUE_NULL.equals(dropBo.getValue()) || "0".equals(dropBo.getValue());
    }

    /**
     * 自定义价格
     *
     * @param dropBo1 最低
     * @param dropBo2 最高
     */
    public static String customPrice(DropBo dropBo1, DropBo dropBo2) {
        double min = TextUtils.isEmpty(dropBo1.getValue()) ?
                0 : Double.parseDouble(dropBo1.getValue());
        double max = TextUtils.isEmpty(dropBo2.getValue()) ?
                0 : Double.parseDouble(dropBo2.getValue());
        if (min == 0) {
            return max >= 10000 ?
                    String.format(Locale.CHINA, "%s万以下",
                            BigDecimal.valueOf(Double.parseDouble(String.format(Locale.CHINA, "%.2f", max / 10000))).stripTrailingZeros().toPlainString()) :
                    String.format(Locale.CHINA, "%.0f元以下", max);
        } else if (max == 0) {
            return min >= 10000 ?
                    String.format(Locale.CHINA, "%s万以上",
                            BigDecimal.valueOf(Double.parseDouble(String.format(Locale.CHINA, "%.2f", min / 10000))).stripTrailingZeros().toPlainString()) :
                    String.format(Locale.CHINA, "%.0f元以上", min);
        } else {
            return min >= 10000 ?
                    String.format(Locale.CHINA, "%s-%s万",
                            BigDecimal.valueOf(Double.parseDouble(String.format(Locale.CHINA, "%.2f", min / 10000))).stripTrailingZeros().toPlainString(),
                            BigDecimal.valueOf(Double.parseDouble(String.format(Locale.CHINA, "%.2f", max / 10000))).stripTrailingZeros().toPlainString()) :
                    String.format(Locale.CHINA, "%.0f-%.0f元", min, max);
        }
    }
}
